#ifndef _m26_h
#define _m26_h
#include "at.h"


#define M26_GPIO_CLK  RCC_APB2Periph_GPIOC
#define M26_GPIO      GPIOC

#define M26_PWRKEY_Pin  GPIO_Pin_10  /* M26 PWRKEY */
#define M26_POWER_Pin   GPIO_Pin_11  /* M26 VBAT:Pin 34/35 */



/** CSQ */
#define SQ_MIN         8
#define SQ_MAX         31
#define SQ_RETRY       20    // 
#define SQ_INTERVAL    1000  // ms

/** Moudle manager  */
#define PWK_DISABLE_FADE_TIME    2000
#define PWK_ENABLE_HOLD_TIME     2000

#define SHUTDOWN_FADE_TIME   16000  // 
#define POWER_OFF_FADE_TIME  15000
#define BOOT_AFTER_SHUTDOWN  8000

#define ON_SETUP_RETRY    3


void M26_InitPort(void);
void M26_EnablePower(void);
void M26_DisablePower(void);
void M26_EnablePwk(void);
void M26_DisablePwk(void);
void M26_Shutdown(void);
void M26_PowerOff(void);
int  M26_Boot(void);
void M26_Reboot(void);


AT_Echo PendAt(uint32_t timeout);
AT_Echo PendBegintWith(char* keyWord, uint16_t timeout);
AT_Echo PendContain(char* keyWord, uint16_t timeout);

AT_Echo WaitAtOk(uint16_t retry);
AT_Echo WaitReady(uint16_t retry);
AT_Echo WaitWord(char* keyWord, uint16_t retry);

AT_Echo QueryBaudRate(uint32_t* baudRate);

AT_Echo QuerySignalQuality(int* n, int* stat);
AT_Echo QueryValidSignalQuality(int* n, int* stat);
AT_Echo QueryGSMSNetStatus(int* n, int* stat);
AT_Echo QueryGPRSNetStatus(int* n, int* stat);
AT_Echo QueryFrontScene(int *id, int* chn);
AT_Echo QuerySIMStatus(void);
AT_Echo QueryIPState(int* n);



AT_Echo ParseGSMStatus(char* str, int* n, int* stat);
AT_Echo ParseGPRSStatus(char* str, int* n, int* stat);


AT_Echo SaveUserConfiguration(int n);
AT_Echo ActiveScene(void);
AT_Echo DeactScene(void);

AT_Echo ConfigATQ(int n);
AT_Echo ConfigBaudRate(uint32_t baudRate);
AT_Echo ConfigGSMNet(int n);
AT_Echo ConfigGPRSNet(int n);
AT_Echo ConfigScene(int id);
AT_Echo ConfigAP(int mode, char* apn);
AT_Echo ConfigTransmissionMode(int mode);


AT_Echo RegisterApp(char* apn, char* username, char* passwd);


AT_Echo Connect(int type, char* ip, int port);
AT_Echo Send(uint8_t* buf, uint16_t size);

AT_Echo TCP_IP_Reach_Process(void);



void WhateverGotoInternet(void);

#endif
